package com.yun.cloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.yun.cloud.entity.Dept;
import com.yun.cloud.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by lsy
 * on 2018/6/8 11:54.
 */
@RestController
public class DeptController {

    @Autowired
    private DeptService service;


    @RequestMapping(value = "/dept/get/{id}", method = RequestMethod.GET)
    @HystrixCommand(fallbackMethod = "processHystrix_Get")
    public Dept get(@PathVariable("id") Long id) {
        Dept dept = service.get(id);
        if (dept == null) {
            throw new RuntimeException("is null");
        }
        return dept;
    }


    public Dept processHystrix_Get(@PathVariable("id") Long id) {
        Dept d = new Dept();
        d.setdName("这个id 没有信息【" + id + "】");
        return d;
    }
}